package com.j2ee.JDKProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 拦截器开发步骤：
 * 1、实现InvocationHandler接口
 * 2、引入目标类和事务类
 * 3、完成invoke方法
 * @author LC
 *
 */
public class MyInterceptor implements InvocationHandler {
	
	private Object target ;
	private Transaction transaction ;
	
	public MyInterceptor(Object target, Transaction transaction) {
		this.target = target;
		this.transaction = transaction;
	}
	
	/**
	 * invoke方法中参数含义：
	 * 		proxy——目标类的代理对象
	 * 		method——代理对象调用的方法作为method的实参
	 */
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		this.transaction.beginTransaction();
		method.invoke(this.target, args);
		this.transaction.commit();
		return null;
	}
	

}
